home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / netprog.zip / NETPROG.TAR / ipc / Calc.sh next >
Linux/UNIX/POSIX Shell Script  |  1989-12-17  |  2KB  |  80 lines

  1. #! /bin/sh
  2.  
  3. # Number of times each program was timed
  4. Nruns=3
  5.  
  6. # Number of loops in each program
  7. Nloop=20000
  8.  
  9. File=/tmp/my$$
  10.  
  11. cat $1 > $File
  12.  
  13. #
  14. # Copy the file above, then edit the file (to join lines).
  15. # The 3b1 puts out times of the form "1m8.76s".  Convert this to "1:8.76"
  16. # then process as a Xenix date.
  17. #
  18.  
  19. ex - $File <<MYEOF
  20. g/^real.*[0-9]*m[0-9]*.[0-9]*s/s/m/:/
  21. g/^real.*[0-9]*:[0-9]*.[0-9]*s/s/s//
  22. g/^user.*[0-9]*m[0-9]*.[0-9]*s/s/m/:/
  23. g/^user.*[0-9]*:[0-9]*.[0-9]*s/s/s//
  24. g/^sys.*[0-9]*m[0-9]*.[0-9]*s/s/m/:/
  25. g/^sys.*[0-9]*:[0-9]*.[0-9]*s/s/s//
  26. g/^real/j2
  27. g/++++++++++/s///
  28. g/message queue,/s//mque,/
  29. g/shared memory,/s//shm, /
  30. x
  31. MYEOF
  32.  
  33. nawk '
  34.  
  35. function cvttime(str) {
  36.     #
  37.     # Xenix puts out times such as "1:14.6" for 74.6 seconds
  38.     #
  39.     if (index(str, ":") > 0) {
  40.         i = split(str, arr, ":")
  41.         if (i != 2) {
  42.             print "split error"
  43.             exit 1
  44.         }
  45.         return(arr[1]*60 + arr[2])
  46.     } else {
  47.         return(str)
  48.     }
  49. }
  50.  
  51. /len = /     { title = $0 }
  52.  
  53. $2 == "real" {    # VAX line is:  I real J user K sys
  54.         # times are of the form 74.6, for example
  55.         counter += 1
  56.         real += $1
  57.         cpu  += $3 + $5
  58.         if (counter == nruns) {
  59.             printf("real = %5.1f, cpu = %5.1f, mesg/sec = %6d: %s\n", real/nruns, cpu/nruns, (nruns*nloop)/real, title)
  60.             real = 0
  61.             cpu  = 0
  62.             counter = 0
  63.         }
  64.     }
  65.  
  66. $1 == "real" {    # PC/AT & UNIX PC line is:  real I user J sys K
  67.         # times are of the form 1:14.6, for example.
  68.         counter += 1
  69.         real += cvttime($2)
  70.         cpu  += cvttime($4) + cvttime($6)
  71.         if (counter == nruns) {
  72.             printf("real = %5.1f, cpu = %5.1f, mesg/sec = %6d: %s\n", real/nruns, cpu/nruns, (nruns*nloop)/real, title)
  73.             real = 0
  74.             cpu  = 0
  75.             counter = 0
  76.         }
  77.     }' nruns=${Nruns} nloop=${Nloop} ${File}
  78.  
  79. rm ${File}
  80.